local skel = fk.CreateSkill {
  name = "emo__biyi",
  tags = {Skill.Compulsory}
}

Fk:loadTranslationTable{
  ["emo__biyi"] = "比翼",
  [":emo__biyi"] = "锁定技，每轮开始时，若你没有发动过此技能，你令一名其他角色获得“翼”标记，然后获得其一张武将牌上的所有技能。当该角色死亡后，你失去以此法获得的技能并获得〖归离〗。",

  ["@@emo__biyi_other"] = "翼",
  ["@emo__biyi"] = "比翼",
  ["#emo__biyi-choose"] = "比翼：令一名其他角色获得“翼”标记，获得其武将牌上的技能",

  ["$emo__biyi1"] = "凰凤化越，彩翼犹存。",
  ["$emo__biyi2"] = "与君有灵犀，一双彩翼，载得许多梦。",
}

skel:addEffect(fk.RoundStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
    and #player.room:getOtherPlayers(player, false) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 2, targets = room:getOtherPlayers(player), skill_name = skel.name,
      cancelable = false, prompt = "#emo__biyi-choose",
    })
    local to = tos[1]
    room:addPlayerMark(to, "@@emo__biyi_other", 1)
    room:setPlayerMark(player, skel.name, to.id)
    local general = to.general
    if Fk.generals[to.deputyGeneral]
    and room:askToChoice(player, { choices = {"mainGeneral", "deputyGeneral"}, skill_name = skel.name}) == "deputyGeneral" then
      general = to.deputyGeneral
    end
    room:setPlayerMark(player, "@emo__biyi", general)
    local skills = {}
    for _, skill_name in ipairs(Fk.generals[general]:getSkillNameList()) do
      local s = Fk.skills[skill_name]
      if not player:hasSkill(s, true) and not (s:hasTag(Skill.Lord) and player.role ~= "lord")
      and not (s:hasTag(Skill.AttachedKingdom) and not table.contains((s:getSkeleton() or {}).attached_kingdom, player.kingdom)) then
        table.insert(skills, s.name)
      end
    end
    if #skills > 0 then
      room:setPlayerMark(player, "emo__biyi_skill", skills)
      room:handleAddLoseSkills(player, table.concat(skills, "|"), nil)
    end
  end,
})

skel:addEffect(fk.Deathed, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target.id == player:getMark(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@emo__biyi", 0)
    local skills = player:getMark("emo__biyi_skill")
    if type(player:getMark("emo__biyi_skill")) == "table" and #skills > 0 then
      room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"))
    end
    room:handleAddLoseSkills(player, "emo__guili")
  end,
})

return skel
